//
//  PendApprovalAreaLayoutTableViewCell.m
//  ZJControlsClass
//
//  Created by mac on 2024/11/29.
//

#import "PendApprovalAreaLayoutTableViewCell.h"

@interface PendApprovalAreaLayoutTableViewCell ()

@property (nonatomic,strong) UIView * v;
@property (nonatomic,strong) NSMutableArray * dataSource;



@end


@implementation PendApprovalAreaLayoutTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        
        [self configUI];
        
        
        
    }
    return self;
}


-(void)configUI{
    
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.inputTextF];
    [self.contentView addSubview:self.v];
    
    
    
    [self.contentView sd_addSubviews:@[self.titleLabel,self.inputTextF,self.v]];
    
    
    self.titleLabel.sd_layout
    .leftSpaceToView(self.contentView, ALIGN_WIDTH_PT(15))
    .topSpaceToView(self.contentView, 0)
    .widthIs(SCREEN_WIDTH / 2 - ALIGN_WIDTH_PT(15))
    .heightIs(ALIGN_HEIGHT_PT(50));
    
    self.inputTextF.sd_layout
    .leftSpaceToView(self.titleLabel, 0)
    .rightSpaceToView(self.contentView, ALIGN_WIDTH_PT(15))
    .topEqualToView(self.titleLabel)
    .heightIs(50);

    self.v.sd_layout
    .leftSpaceToView(self.contentView, ALIGN_WIDTH_PT(10))
    .rightSpaceToView(self.contentView, ALIGN_WIDTH_PT(10))
    .topSpaceToView(self.titleLabel, 1)
    .heightIs((1));
    
    
    
}

-(void)setParamer:(NSMutableDictionary *)paramer{
    _paramer = paramer;
    self.titleLabel.text = paramer[@"title"];
    
    NSData *jsonData = [paramer[@"temp"] dataUsingEncoding:NSUTF8StringEncoding];
    
    NSError *error;
    NSMutableArray * array = @[].mutableCopy;
    array = [NSJSONSerialization JSONObjectWithData:jsonData options:kNilOptions error:&error];
    
    NSLog(@"=====-----444444%@",array);
    if (error) {
        NSLog(@"JSON解析出错：%@", error);
        [LUtilityTools showAlertWithTitle:@"温馨提示" message:[NSString stringWithFormat:@"JSON解析formItems出错：%@", error] buttonAction:^{
            
        }];
        
        return;
    }
    
    [self.dataSource addObjectsFromArray:array];
    
    NSMutableArray * te = @[].mutableCopy;
    [self.dataSource enumerateObjectsUsingBlock:^(NSArray * obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [obj enumerateObjectsUsingBlock:^(id  _Nonnull obj1, NSUInteger idx, BOOL * _Nonnull stop) {
            [te addObject:obj1];
        }];
    }];
    
    NSMutableArray * strArr = @[].mutableCopy;
    [te enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [strArr addObject:obj[@"name"]];
    }];
    NSString * str = [strArr componentsJoinedByString:@","];
    
        // 计算高度
        NSMutableAttributedString * attriBedString = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@",str]];
        UIFont * font = FONT14;
        NSMutableParagraphStyle * style = [[NSMutableParagraphStyle alloc]init];
        style.lineSpacing = ALIGN_HEIGHT_PT(5);
        [attriBedString addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, str.length)];
        [attriBedString addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, str.length)];
        self.inputTextF.attributedText = attriBedString;


        NSStringDrawingOptions  options = NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading;
        CGFloat lableSize = [attriBedString boundingRectWithSize:CGSizeMake(SCREEN_WIDTH / 2 - ALIGN_WIDTH_PT(30), MAXFLOAT) options:options context:nil].size.height;

        if (lableSize < 50){

            self.inputTextF.sd_layout
                .heightIs(ALIGN_HEIGHT_PT(50));
            self.v.sd_layout
                .topSpaceToView(self.inputTextF, 0);

        }else{

            self.inputTextF.sd_layout
                .heightIs(lableSize);
            self.v.sd_layout
                .topSpaceToView(self.inputTextF, 10);

        }
    
        [self setupAutoHeightWithBottomView:self.v bottomMargin:0];

    
}


#pragma mark -- 懒加载
-(UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [UILabel new];
        _titleLabel.text = @"*申办单位全称";
        _titleLabel.font = FONT14;
        _titleLabel.textColor = COLOR_RGB(153, 153, 153);
        _titleLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _titleLabel;
}

-(UILabel *)inputTextF{
    if (!_inputTextF) {
        _inputTextF = [UILabel new];
        _inputTextF.textColor = [UIColor blackColor];
        _inputTextF.font = FONT14;
        _inputTextF.textAlignment = NSTextAlignmentLeft;
        _inputTextF.numberOfLines = 0;
    }
    return _inputTextF;
}

-(UIView *)v{
    if (!_v) {
        _v = [UIView new];
        _v.backgroundColor = COLOR_RGB(215, 216, 217);
    }
    return _v;
}

-(NSMutableArray *)dataSource{
    if (!_dataSource){
        _dataSource = [NSMutableArray array];
    }
    return _dataSource;
}


@end
